package com.sh.二叉树;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class 二叉树的中序遍历 {
    public static void main(String[] args) {

    }
    public List<Integer> inorderTraversal(TreeNode root) {
        if (root==null){
            return Arrays.asList(null);
        }
        Stack<TreeNode> stack = new Stack<>();
        List<Integer> res = new ArrayList<>();
        TreeNode temp = root;
        while (stack.isEmpty()==false || temp!=null){
            if (temp!=null){
                stack.push(temp);
                temp = temp.left;
            }else {
                temp = stack.pop();
                res.add(temp.val);
                temp = temp.right;
            }
        }
        return res;
    }

    public static void fun(TreeNode node , List list){
        if (node==null){
            return;
        }
        fun(node.left, list);
        list.add(node.val);
        fun(node.right, list);

    }

}

